//
//  SandBoxHandler.m
//  沙盒
//
//  Created by dllo on 16/3/29.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "SandBoxHandler.h"

@implementation SandBoxHandler

+ (instancetype)sanBoxHandler {
    return [[SandBoxHandler alloc] init];
}

+ (NSString *)pathOfDocuments {
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}

+ (NSString *)saveInDocumentWithfileName:(NSString *)fileName {
    return [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:fileName];
}

+ (NSString *)saveInSanBoxHandler:(sandBoxType)sandBoxDirctoryType withFileName:(NSString *)fileName {
    switch (sandBoxDirctoryType) {
        case 0:
        {
            return [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:fileName];
            break;
        }
        case 1:
        {
            return [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:fileName];
            break;
        }
        case 2:
        {
            return [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:fileName];
            break;
        }
            
        default:
            break;
    }
}

- (NSString *)pathOfDocuments {
    return [SandBoxHandler pathOfDocuments];
}

- (NSString *)pathOfSandBox {
    return NSHomeDirectory();
}

- (NSString *)pathOfLibrary {
    return [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
}

- (NSString *)pathOfCaches {
    return [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
}

- (NSString *)pathOfTemp {
    return NSTemporaryDirectory();
}

- (NSString *)pathOfPreferences {
    return [[self pathOfLibrary] stringByAppendingPathComponent:@"preferences"];
}

- (NSString *)pathOfAppBundle {
    return [NSBundle mainBundle].resourcePath;
}

@end
